Skip to content

Fix translated posts losing secondary link placeholders#18

Merged
Rocket-Space merged 1 commit intomasterfrom
codex/fix-translation-issues-with-hyperlinks
Feb 26, 2026
Merged

Fix translated posts losing secondary link placeholders#18
Rocket-Space merged 1 commit intomasterfrom
codex/fix-translation-issues-with-hyperlinks

Conversation

@Rocket-Space
Copy link
Owner

Motivation

  • Translation providers (Google/Baidu/etc.) sometimes alter or inject spaces into placeholder tokens, which caused only the first link to be restored or left unresolved markers like __SG_LINK_0__ in translated text.
  • The change aims to make client-side masking/restoration of link placeholders resilient to provider-side token mutation so all links remain clickable after translation.

Description

  • Added a helper findPlaceholderRange that first tries exact match and then uses a regex tolerant to inserted whitespace around underscores to locate mutated placeholders in translated output.
  • Removed surrounding spaces from the placeholder token when masking (use "__SG_LINK_n__" instead of " __SG_LINK_n__ ") to reduce provider-side splitting.
  • Restored link visible text using the located placeholder ranges and remapped entity offsets via the existing cloneLinkEntity so original link entities remain clickable.
  • Changes made in TMessagesProj/src/main/java/org/telegram/ui/Components/TranslateAlert2.java and added imports for Matcher and Pattern.

Testing

  • Attempted to compile with ./gradlew -q :TMessagesProj:compileDebugJavaWithJavac to validate Java changes, but the build failed in this environment with Unsupported class file major version 69, an unrelated Java/Gradle compatibility issue.
  • No additional automated tests were run in this environment due to the compile failure; the change is small and limited to placeholder handling logic.

Codex Task

@chatgpt-codex-connector
Copy link

You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard.

@Rocket-Space Rocket-Space merged commit fbca034 into master Feb 26, 2026
1 check passed
@Rocket-Space Rocket-Space deleted the codex/fix-translation-issues-with-hyperlinks branch February 26, 2026 08:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant